import 'package:dependencies_examples/permission/permission_utils.dart';
import 'package:dependencies_examples/utils/UiUtils.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

class PermissionPage extends StatelessWidget {
  const PermissionPage({super.key});

  static const String permissionPageTitle = 'Permission Page';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text(permissionPageTitle)),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () async {
                final status = await PermissionUtils
                    .checkAndRequestPermission(Permission.camera);
                if (context.mounted) {
                  if (status.isGranted) {
                    UiUtils.showSnackBar(context, 'Camera permission granted');
                  } else if (status.isDenied) {
                    UiUtils.showSnackBar(context, 'Camera permission denied');
                  } else if (status.isPermanentlyDenied) {
                    UiUtils.showSnackBar(
                      context,
                      'Camera permission permanently denied, please enable it in settings.',
                    );
                    await openAppSettings();
                  } else {
                    if (kDebugMode) {
                      print('Camera permission status: ${status.toString()}');
                    }
                  }
                }
              },
              child: const Text('Request Camera Permission'),
            ),
            ElevatedButton(
              onPressed: () async {
                // You can request multiple permissions at once.

              },
              child: Text('bluetooth permissions'),
            ),
          ],
        ),
      ),
    );
  }
}
